function [amps, freqs, phases] = SinAnalysis(x, nFrames, samPerFra, nFFT, hopSamples, winType, maxPeaks)
%SINANALYSIS decompose the wave into peaks 
%   peaks are described by amplitudes, frequencies and phases

window_gen = str2func(winType);
w = window_gen(samPerFra);

% VECTOR VARIABLES DECLARATION
amps = zeros(maxPeaks,nFrames);
freqs = zeros(maxPeaks,nFrames);
phases = zeros(maxPeaks,nFrames);

for frameIdx=1:nFrames
    
    xIdx = 1:samPerFra;
    xFrame = zeros(nFFT, 1);
    xFrame(xIdx) = x((frameIdx-1)*hopSamples + xIdx);
    xFrame(xIdx) = xFrame(xIdx) .* w / sum(w); % windowing & preserve energy
    xFrame = [xFrame(floor(samPerFra/2)+1:end);xFrame(1:floor(samPerFra/2))];     %linear phase to zero phase  

    X = fft(xFrame, nFFT);                      % DFT
    
    [ampsInFra,freqsInFra,phasInFra]=FindPeaksWithinFrame(X, maxPeaks);
    amps(:, frameIdx) = ampsInFra;          % dB
    freqs(:, frameIdx) = freqsInFra;        % rad/sample
    phases(:, frameIdx) = phasInFra;        % degree 
    
end
